home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 20 / Cream of the Crop 20 (Terry Blount) (1996).iso / program / n_b_v203.zip / R&W-BLOK.DMO < prev    next >
Text File  |  1996-07-04  |  6KB  |  85 lines

  1. $if 0
  2.     ┌──────────────────────────╖                        PowerBASIC v3.20
  3.  ┌──┤          DASoft          ╟──────────────────────┬──────────────────╖
  4.  │  ├──────────────────────────╢    Copyright 1995    │ DATE: 1995-10-01 ╟─╖
  5.  │  │ FILE NAME   R&W-BLOK.DMO ║          by          ╘════════════════─ ║ ║
  6.  │  │                          ║  Don Schullian, Jr.                     ║ ║
  7.  │  ╘══════════════════════════╝                                         ║ ║
  8.  │ A license is hereby granted to the holder to use this source code in  ║ ║
  9.  │ any program, commercial or otherwise,  without receiving the express  ║ ║
  10.  │ permission of the copyright holder and without paying any royalties,  ║ ║
  11.  │ as long as this code is not distributed in any compilable format.     ║ ║
  12.  │  IE: source code files, PowerBASIC Unit files, and printed listings   ║ ║
  13.  ╘═╤═════════════════════════════════════════════════════════════════════╝ ║
  14.    │                ....................................                   ║
  15.    ╘═══════════════════════════════════════════════════════════════════════╝
  16. $endif
  17.  
  18. '.°.°.°.°.°.°.°.°.°.°.°.°.°.°.°.°.°.°.°.°.°.°.°.°.°.°.°.°.°.°.°.°.°.°.°.°.°.°
  19. ' ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° °
  20.  
  21. $INCLUDE "DAS-NB01.INC"
  22. $INCLUDE "DAS-NB02.INC"
  23. COLOR 7,0
  24. CLS
  25.  
  26. ? "┌────────────────────────────────────────────────────────────────────────────
  27. ? "│ fWriteBlock?   (Handle%,ANY,Bytes??)    fReadBlock?   (Handle%,ANY,Bytes??)
  28. ? "│ fWriteBlockPtr?(Handle%,P???,Bytes??)  fReadBlockPtr?(Handle%,P???,Bytes??)
  29. ? "├─────────────────────────────────────────────────────────────────────────────
  30. ? "│ These do for numeric arrays what fWriteI and fReadI do for numeric variables.
  31. ? "│ Now, however, the saving in typing, time and code is much greater as the R/W
  32. ? "│ takes place directly from/to memory bypassing PowerBASIC completely.
  33. ? "│ The functions on the second line above are the same except that they use
  34. ? "│ far-pointers to the data instead of a numeric array element.
  35. ? "├─────────────────────────────────────────────────────────────────────────────
  36. ? "│ SEE: FSEEK.TXT
  37. ? "└─────────────────────────────────────────────────────────────────────────────
  38.                                                   '┌────────────────────────
  39. F$   = "DUMMY.DAT"                                '│ a junk file
  40. DIM Arr%(99)                                      '│
  41. QLoadIarr Arr%(0), 0, 100                         '│
  42.                                                   '│
  43. OPEN "B", #1, F$                                  '│ open the file
  44.   Handle% = FILEATTR( 1, 2 )                      '│ get DOS's file handle
  45.                                                   '│
  46.   fWriteBlock Handle%, Arr%(0), 200               '│ write 200 bytes to file
  47.   REDIM Arr%(99)                                  '│ set array elements = 0
  48.   SEEK #1, 0                                      '│ back to the top
  49.   fReadBlock Handle%, Arr%(0), 200                '│ read 200 bytes from file
  50.                                                   '│
  51.   FOR X% = 0 TO 99                                '│ display the 100 elements
  52.     PRINT USING "### "; Arr%(X%);                 '│
  53.   NEXT                                            '│
  54.                                                   '├─────────────────────────
  55.   SEEK #1, 0                                      '│ time test!
  56.   MTIMER                                          '│
  57.    fWriteBlock Handle%, Arr%(0), 200              '│ this equals >>─────────┐
  58.   DASoft = MTIMER                                 '│                        │
  59.                                                   '│                        │
  60.   SEEK #1, 0                                      '│                        │
  61.                                                   '│                        │
  62.   MTIMER                                          '│                        │
  63.    DEF SEG   = VARSEG( Arr%(0) )                  '│ <<───┐ all of this! <<─┘
  64.    Ptr%      = VARPTR( Arr%(0) )                  '│      │
  65.    Bytes&    = 200                                '│      │ not to mention
  66.    MaxBytes% = 1024                               '│      │ the free error
  67.    DO                                             '│      │ trapping :-)
  68.      B% = MIN( MaxBytes%, Bytes& )                '│      │
  69.      DECR Bytes&, B%                              '│      │
  70.      INCR B%, B%                                  '│      │
  71.      D$ = PEEK$( Ptr%, B% )                       '│      │
  72.      PUT$ #1, D$                                  '│      │
  73.      INCR Ptr%, B%                                '│      │
  74.    LOOP UNTIL Btyes& < 1                          '│      │
  75.    DEF SEG                                        '│ <<───┘
  76.   PBasic = MTIMER                                 '│
  77.                                                   '│
  78.   PRINT                                           '│
  79.   PRINT       "Elapsed times:"                    '│
  80.   PRINT USING " DASoft#,### m/sec"; DASoft        '│
  81.   PRINT USING " PBasic#,### m/sec"; PBasic        '│
  82.                                                   '│
  83. CLOSE #1                                          '│ close the file
  84. KILL F$                                           '│ keep your HD clean!
  85.                                                   '└─────────────────────────